package com.renbang.action.devoloper;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.TreeMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.renbang.dao.sqlsession.DBUtils;
import com.renbang.model.common.AjaxResult;
import com.renbang.utils.drawandindex.Higlight;
import com.renbang.utils.drawandindex.Word;
import com.renbang.utils.excel.ExcelImport;
import com.renbang.utils.lire.Searcher;

@Controller
@RequestMapping(value = "developer/lire")
public class lireAction {
	@Autowired
	SqlSessionTemplate sqlSession;
	@RequestMapping(value = "/search")
	public @ResponseBody AjaxResult searchchart(HttpServletResponse response,
				HttpServletRequest request,
				@RequestParam(value = "file", required = false) MultipartFile file)
				throws Exception {
			response.setContentType("text/html;charset=UTF-8");
			String fileName = file.getOriginalFilename();
			System.out.println("lireAction.searchchart()"+fileName);
			String dirPath = request.getSession().getServletContext()
					.getRealPath("/")
					+ "fileupload";
			System.out.println("lireAction.searchchart()"+dirPath);
			File fileDir = new File(dirPath);
			if (!fileDir.exists()||!fileDir.isDirectory()) {
				if (fileDir.mkdirs()) {
				}
			}
			File saveFile = new File(dirPath + "/" + fileName);
			try {
				file.transferTo(saveFile);
				List<String> list = Searcher.search(saveFile);
				System.out.println(list);
				/*System.out.println(list.get(0).size());
				DBUtils.createTemp(list.get(0).size());
				DBUtils.insertTemp(list, list.get(0).size());
				return new AjaxResult(AjaxResult.STATUS_OK, "加载成功","1",list,list.size());*/
			} catch (IllegalStateException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return null;
		}
}